
// import TableList from "@components/templates/tablelist";
import TableList from "@components/templates/customtablelist";
import { HttpCarrierServiceBlackList, HttpGetProductByOrgLabel, HttpGetProductServiceByOrg, HttpChangeCCarrierServiceBlackStatus } from '@/service/api/views'
import { mapState, mapGetters } from "vuex";
import compUpdate from './update.vue';
import mixins from '../mixin'
export default {
    mixins: [TableList,mixins],
    components: {
        compUpdate
    },
    data () {
        return {
            // totals: 0,
            isMixin: true,
            Tools: { show: true },
            formData: {
                search: {
                }
            },
            Searchs: {
                show: true,
                labelWidth: 120,
            },
            Plugins: { show: true },
            carrierList:[],
            exportData:{},
            serviceList: {},
        }
    },
    created(){
        HttpGetProductByOrgLabel({customerId: global.SYSID}).then(res=>{
            this.loading = false
            this.carrierList = res.data.map(item=>{
                return {value: item.id, label: item.carrierGroupCode, attach: item}
            })
        },err=>{
            this.loading = false
            this.$Message.error({
                content: err.message,
                duration: 30,
                closable: true,
            });
        })
        HttpGetProductServiceByOrg({'search[EQ_active]': 1}).then(res=>{
            this.serviceList = res.data.map(item=>{
                return {value: item.id, label: item.carrierServiceCode, attach: item}
            })
        },err=>{
            this.$Message.error({
                content: err.message,
                duration: 30,
                closable: true,
            });
        })
    },
    methods: {
        ajaxRequest: HttpCarrierServiceBlackList,
        interceptRequest (params) {
            this.exportData = params;
            return params
        },
        // toolsRender() { //自定义工具行
        //     return <div style="background: #fff;margin-bottom: 10px;padding: 5px;padding-left: 10px;">
        //             <Button type="primary" onClick={this.handleOperates.bind(this,{},'add')} icon="plus">添加</Button>
        //         </div>
        // },
        handleOperates (params = "", type, batch) {
            if (batch === true) {
                params = (params || this.checkedData.join(',')) + '';
                if (!params.length) return this.$Message.warning('请选择至少一条数据');
            }
            switch (type) {
                case 'add':
                    this.operate = {
                        show: true,
                        title: "添加黑名单",
                        component: "compUpdate",
                        querytype: 'add',
                        width: 1200,
                        showFooter: false
                    };
                    break;
                case 'edit':
                    var url2 = this.$router.resolve({
                        name: 'tmsCarrierBlackListUpdate',
                        params: { type },
                        query: { id: params },
                    });
                    window.open(url2.href, '_blank');
                    break;
                case 'changeStatus':
                    return new Promise((resolve) => {
                        this.operate = {
                            show: true,
                            alert: 'warning',
                            params: { id: params.id },
                            title: "修改状态",
                            ajaxRequest: HttpChangeCCarrierServiceBlackStatus,
                            callback:()=>{
                                this.$emit('on-update');
                                this.operate = {};
                            }
                        }
                    })
            }
        },
        getOperateNodeMap(row) {
            const { id } = row;
            return [
                {
                    label: "编辑",
                    show: true,
                    params: id,
                    operate: "edit"
                },
            ];
        }
    },
    computed: {
        ...mapGetters('dictionary', ['getBillcusorgList', 'getUserManageWarehouseList', 'getAlllogProCodeList', 'getCarrierAll']),
        ToolsData(){
            return [
                {
                    name: "添加",
                    theme: 'primary',
                    operate: 'add',
                },
            ]
        },
        // 搜索下拉框展示内容
        SearchsData () {
            return [
                {
                    label: "客户组织",
                    tag: 'Select',
                    options:this.getBillcusorgList,
                    key: 'EQ_organizationId',
                    show:true,
                    props:{
                        filterable:true,
                    },
                },
                {
                    label: "仓库",
                    tag: 'Select',
                    options: this.getUserManageWarehouseList.map(item=>{
                        return {
                            value: item.attach.id,
                            label: item.label
                        }
                    }),
                    key: 'EQ_orgWarehouseId',
                    show: false,
                    props:{
                        filterable:true,
                    },
                },
                {
                    label: '物流产品',
                    tag: 'Select',
                    options:this.carrierList,
                    key: 'EQ_carrierGroupId',
                    show:true,
                    props:{
                        filterable:true,
                    },
                },
                {
                    label: '承运商服务',
                    tag: 'Select',
                    key: 'EQ_carrierServiceId',
                    options:this.serviceList,
                    show:true,
                    props:{
                        filterable:true,
                    }
                },
            ]
        },
        // table的展示数据
        columns () {
            return [
                {
					title: "序号",
					type: 'index',
                    align: "center",
					width: 60
				},
                {
                    title: "操作",
                    width: 90,
                    render: this.getOperateNodes
                },
                {
					title: "客户组织",
                    key: "organizationId",
                    render: (h, {row})=>{
                        let org =this.getBillcusorgList.filter(item=>item.value == row.organizationId)[0];
                        return org ? org.label : '--';
                    },
                    align: "center",
                    minWidth: 120
				},
                {
					title: "仓库",
                    key: "orgWarehouseCode",
                    align: "center",
					minWidth: 120
				},
                {
					title: "物流产品",
                    key: "carrierGroupCode",
                    align: "center",
					minWidth: 120
				},
                {
					title: "承运商服务",
                    key: "carrierServiceCode",
                    align: "center",
					minWidth: 120
				},
                {
					title: "状态",
                    key: "active",
                    align: "center",
					width: 80,
                    render: (h, { row }) => {
                        let active = row.active == 1 ? true : false;
                        return <Switch v-model={active} before-change={this.handleOperates.bind(this, { id:row.id }, 'changeStatus')}/>
                    }
				},
                {
                    title: "创建时间",
                    align: "center",
                    render: (h, { row })=>{
                        return <div>{row.createdAt || '--'}</div>
                    }
                },
            ];
        },

    },

};
